﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using He.Web.UI;

namespace He.Web.manage.tools
{
    public partial class copy : He.Web.UI.Manage
    {
       
        public int fromChannelId = 0;
        public int toChannelId = 0;
        public int fromCategoryId = 0;
        public int toCategoryId = 0;

        public string action = InputUtil.Form("act");

        public string is_translate = InputUtil.Form("is_translate");
        public string clear_tags = InputUtil.Form("clear_tags");
        public string make_thumb = InputUtil.Form("make_thumb");
        public int img_width;

        public string copy_all = InputUtil.Form("copy_all");
        public string copy_child = InputUtil.Form("copy_child");
        public string idlist = InputUtil.Form("idlist");

        public string threadKey = DateTime.Now.ToFileTime().ToString();
        protected void Page_Load(object sender, EventArgs e)
        {
            chkLoginLevel("data_copy");

            if (!this.Page.IsPostBack)
            {
                if (action == "copy_channel")
                {
                    if (!int.TryParse(InputUtil.Form("ddlFromChannelId"), out fromChannelId))
                    {
                        ShowParamError("请选择要拷贝的栏目。");
                        return;
                    }

                    if (!int.TryParse(InputUtil.Form("ddlToChannelId"), out toChannelId))
                    {
                        ShowParamError("请选择要拷贝到的栏目。");
                        return;
                    }

                    //判断两者栏目模型是否匹配
                    BLL.channel bll = new BLL.channel();
                    Model.channel channel = bll.GetModel(fromChannelId);
                    Model.channel to_channel = bll.GetModel(toChannelId);
                    if (channel.model_id != to_channel.model_id)
                    {
                        ShowParamError("两个栏目的数据结构不匹配，请重新选择栏目。");
                        return;
                    }

                    if (idlist == "")
                    {
                        ShowParamError("请选择要拷贝的分类。");
                        return;
                    }
                }
                else
                {
                    if (!int.TryParse(InputUtil.Form("ddlFromCategoryId"), out fromCategoryId))
                    {
                        ShowParamError("请选择要拷贝的分类");
                        return;
                    }
                    if (!int.TryParse(InputUtil.Form("ddlToCategoryId"), out toCategoryId))
                    {
                        ShowParamError("请选择要拷贝到的分类");
                        return;
                    }
                    if (copy_all != "1")
                    {
                        if (idlist == "")
                        {
                            ShowParamError("请选择要拷贝的内容。");
                            return;
                        }
                    }
                }

                if (!int.TryParse(InputUtil.Form("img_width"), out img_width))
                {
                    ShowParamError("请输入整数的图片宽度值。");
                    return;
                }
            }
        }
    }
}